<?php require ("utils.php");
//=====================================================language=============================================
if($_SESSION['langname']=="")
{
	$language_url="languages/"."english".'/checkout_add_language.php';
}
else
{
	$language_url="languages/".$_SESSION['langname'].'/checkout_add_language.php';
}

include_once("$language_url");
//======================================================End============================================
if($_SESSION['siteuserId']=="")
{
	header("location:start.php");
}
$value	=	$_REQUEST['mode'];
switch($_REQUEST['mode'])
{
	case insert:	insert_shipping_billing();
					break;																								
	default:	main_content("main();");
}
function main()
{
	if($_SESSION['siteuserId']!="")
	{
		 $que="select * from siteusers where siteuserId='".$_SESSION['siteuserId']."'";
		
		//$row_billing_details=mysql_fetch_array(mysql_query("select * from siteusers where siteuserId='".$_SESSION['siteuserId']."'"));	

		$row_billing_details_pay=mysql_fetch_array(mysql_query("select * from payment_method where userId='".$_SESSION['siteuserId']."'"));
				 	
		$billing_fname=stripslashes($row_billing_details_pay[billing_fname]);
		$billing_lname=stripslashes($row_billing_details_pay[billing_lname]);
		$billing_address1=stripslashes($row_billing_details_pay[billing_address1]);
		$billing_address2=stripslashes($row_billing_details_pay[billing_address2]);
		$billing_city=stripslashes($row_billing_details_pay[city]);
		$billing_country=stripslashes($row_billing_details_pay[countryId]);
		$billing_state=stripslashes($row_billing_details_pay[stateId]);
		$billing_zip=stripslashes($row_billing_details_pay[zip]);
		$billing_phone=stripslashes($row_billing_details_pay[billing_phone]);
		$billing_fax=stripslashes($row_billing_details_pay[billing_fax]);
		$billing_email=stripslashes($row_billing_details_pay[billing_email]);
		$billing_company=stripslashes($row_billing_details_pay[billing_company]);

		$shipping_fname=stripslashes($row_billing_details_pay[shipping_fname]);
		$shipping_lname=stripslashes($row_billing_details_pay[shipping_lname]);
		$shipping_address1=stripslashes($row_billing_details_pay[shipping_address1]);
		$shipping_address2=stripslashes($row_billing_details_pay[shipping_address2]);
		$shipping_city=stripslashes($row_billing_details_pay[shipping_city]);
		$shipping_country=stripslashes($row_billing_details_pay[shipping_country]);
		$shipping_state=stripslashes($row_billing_details_pay[shipping_state]);
		$shipping_zip=stripslashes($row_billing_details_pay[shipping_zip]);
		$shipping_phone=stripslashes($row_billing_details_pay[shipping_phone]);
		$shipping_fax=stripslashes($row_billing_details_pay[shipping_fax]);
		$shipping_email=stripslashes($row_billing_details_pay[shipping_email]);
		$shipping_company=stripslashes($row_billing_details_pay[shipping_company]);

	}

?>
<script type="text/javascript">
function ajaxstate(country)
{

	if (country == '')
	{ 
		document.getElementById("sltOnChange").innerHTML="";
		return;
	}
	 xmlHttp1=GetXmlHttpObject1()
	if (xmlHttp1==null)
 	 {
		alert ("Your browser does not support AJAX!");
		return;
  	} 
	else
	{
		var url="bill_state.php";
		url =url+"?country="+country;
		xmlHttp1.open("GET",url,true);
		xmlHttp1.onreadystatechange=stateChanged1;
		xmlHttp1.send(null);
	}
}
function stateChanged1() 
{ 
	if (xmlHttp1.readyState==4)
	{ 
		document.getElementById("sltGeneral").style.display="None";
		document.getElementById("sltOnChange").innerHTML=xmlHttp1.responseText;
		
	}
}
function ajaxstate1(country)
{
	if (country == '')
	{ 
		document.getElementById("sltOnChange1").innerHTML="";
		return;
	}
	 xmlHttp1=GetXmlHttpObject1()
	if (xmlHttp1==null)
 	 {
		alert ("Your browser does not support AJAX!");
		return;
  	} 
	else
	{
		var url="shipp_state.php";
		url =url+"?country="+country;
		xmlHttp1.open("GET",url,true);
		xmlHttp1.onreadystatechange=stateChanged2;
		xmlHttp1.send(null);
	}
}
function stateChanged2() 
{ 

	if (xmlHttp1.readyState==4)
	{ 
		document.getElementById("sltGeneral1").style.display="None";
		document.getElementById("sltOnChange1").innerHTML=xmlHttp1.responseText;
		
	}
}
function GetXmlHttpObject1()
{
var xmlHttp1=null;
try
  {
  xmlHttp1=new XMLHttpRequest();
  }
catch (e)
  {
  try
    {
    xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp1;
}
</script>
<script language="JavaScript">
function checkFields()
{
	if(document.frmBillingShipping.billing_fname.value.search(/\S/)==-1)
	{
		//alert("Please Enter Billing First Name");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_BILLING_FIRST_NAME; ?>";
		document.frmBillingShipping.billing_fname.focus();
		return false;
	}
	if(document.frmBillingShipping.billing_lname.value.search(/\S/)==-1)
	{
		//alert("Please Enter Billing Last Name");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_BILLING_LAST_NAME; ?>";
		document.frmBillingShipping.billing_lname.focus();
		return false;
	}
	if(document.frmBillingShipping.billing_address1.value.search(/\S/)==-1)
	{
		//alert("Please Enter Billing Address1");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_BILLING_ADDRESS1; ?>";
		document.frmBillingShipping.billing_address1.focus();
		return false;
	}
	if(document.frmBillingShipping.billing_city.value.search(/\S/)==-1)
	{
		//alert("Please Enter Billing City");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_BILLING_CITY; ?>";
		document.frmBillingShipping.billing_city.focus();
		return false;
	}
	if(document.frmBillingShipping.billing_country.value.search(/\S/)==-1)
	{
		//alert("Please Enter Billing Country");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_BILLING_COUNTRY; ?>";
		document.frmBillingShipping.billing_country.focus();
		return false;
	}
	if(document.frmBillingShipping.billing_zipcode.value.search(/\S/)==-1)
	{
		//alert("Please Enter Billing Zipcode");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_BILLING_ZIP; ?>";
		document.frmBillingShipping.billing_zipcode.focus();
		return false;
	}
	if(document.frmBillingShipping.billing_phone.value.search(/\S/)==-1)
	{
		//alert("Please Enter Billing Phone No");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_BILLING_PHONE; ?>";
		document.frmBillingShipping.billing_phone.focus();
		return false;
	}
	if(document.frmBillingShipping.billing_email.value.search(/\S/)==-1)
	{
		//alert("Please Enter Billing Email");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_BILLING_EMAIL; ?>";
		document.frmBillingShipping.billing_email.focus();
		return false;
	}
	if(document.frmBillingShipping.billing_email.value)
	{
		var x = document.frmBillingShipping.billing_email.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)==false)
		{	
			//alert("Email ID is Not Valid.");
			document.getElementById('text_val').innerHTML="<?php echo ALERT_BILLING_EMAIL_VALID; ?>";
			document.frmBillingShipping.billing_email.select();
			return false;
		}

	} 
	if(document.frmBillingShipping.shipping_fname.value.search(/\S/)==-1)
	{
		//alert("Please Enter Shipping First Name");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_SHIPPING_FIRST_NAME; ?>";
		document.frmBillingShipping.shipping_fname.focus();
		return false;
	}
	if(document.frmBillingShipping.shipping_lname.value.search(/\S/)==-1)
	{
		//alert("Please Enter Shipping Last Name");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_SHIPPING_LAST_NAME; ?>";
		document.frmBillingShipping.shipping_lname.focus();
		return false;
	}
	if(document.frmBillingShipping.shipping_address1.value.search(/\S/)==-1)
	{
		//alert("Please Enter Shipping Address1");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_SHIPPING_ADDRESS1; ?>";
		document.frmBillingShipping.shipping_address1.focus();
		return false;
	}
	if(document.frmBillingShipping.shipping_city.value.search(/\S/)==-1)
	{
		//alert("Please Enter Shipping City");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_SHIPPING_CITY; ?>";
		document.frmBillingShipping.shipping_city.focus();
		return false;
	}
	if(document.frmBillingShipping.shipping_country.value.search(/\S/)==-1)
	{
		//alert("Please Enter Shipping Country");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_SHIPPING_COUNTRY; ?>";
		document.frmBillingShipping.shipping_country.focus();
		return false;
	}
	if(document.frmBillingShipping.shipping_zipcode.value.search(/\S/)==-1)
	{
		//alert("Please Enter Shipping Zipcode");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_SHIPPING_ZIP; ?>";
		document.frmBillingShipping.shipping_zipcode.focus();
		return false;
	}
	if(document.frmBillingShipping.shipping_phone.value.search(/\S/)==-1)
	{
		//alert("Please Enter Shipping Phone No");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_SHIPPING_PHONE; ?>";
		document.frmBillingShipping.shipping_phone.focus();
		return false;
	}
	if(document.frmBillingShipping.shipping_email.value.search(/\S/)==-1)
	{
		//alert("Please Enter Shipping Email");
		document.getElementById('text_val').innerHTML="<?php echo ALERT_SHIPPING_EMAIL; ?>";
		document.frmBillingShipping.shipping_email.focus();
		return false;
	}
	if(document.frmBillingShipping.shipping_email.value)
	{
		var x = document.frmBillingShipping.shipping_email.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)==false)
		{	
			//alert("Email ID is Not Valid.");
			document.getElementById('text_val').innerHTML="<?php echo ALERT_SHIPPING_EMAIL_VALID; ?>";
			document.frmBillingShipping.shipping_email.select();
			return false;
		}

	} 
	document.frmBillingShipping.mode.value="insert";
	document.frmBillingShipping.submit();
	return true;
}
function shippBillSame()
{
	
//alert(document.frmBillingShipping.billing_country.value);
document.frmBillingShipping.shipping_fname.value=document.frmBillingShipping.billing_fname.value;
	document.frmBillingShipping.shipping_lname.value=document.frmBillingShipping.billing_lname.value;
	document.frmBillingShipping.shipping_company.value=document.frmBillingShipping.billing_company.value;
	document.frmBillingShipping.shipping_address1.value=document.frmBillingShipping.billing_address1.value;
	document.frmBillingShipping.shipping_address2.value=document.frmBillingShipping.billing_address2.value;
	document.frmBillingShipping.shipping_city.value=document.frmBillingShipping.billing_city.value;
	document.frmBillingShipping.shipping_country.value=document.frmBillingShipping.billing_country.value;
	var state=document.frmBillingShipping.billing_state.value;
	if(state==null)
	{
		document.frmBillingShipping.shipping_state.value=document.getElementById("billing_state").value;
		
	}
	else
	{
		document.frmBillingShipping.shipping_state.value=document.frmBillingShipping.billing_state.value;
	}
	document.frmBillingShipping.shipping_zipcode.value=document.frmBillingShipping.billing_zipcode.value;
	document.frmBillingShipping.shipping_phone.value=document.frmBillingShipping.billing_phone.value;
	document.frmBillingShipping.shipping_fax.value=document.frmBillingShipping.billing_fax.value;
	document.frmBillingShipping.shipping_email.value=document.frmBillingShipping.billing_email.value;
}
</script>
<!--<form action="<?php// echo $_SERVER['PHP_SELF']; ?>" method="post" name="frmBillingShipping">
<input type="hidden" name="mode">-->
<table width="90%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td valign="top" align="center"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="20%" valign="top"><?php include("left_pannel.php"); ?></td>
                    <td width="10px">&nbsp;</td>
                    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td class="PinkTwosideBorder" valign="top">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="frmBillingShipping">
<input type="hidden" name="mode">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td align="left">&nbsp;</td>
	  </tr>
	  <tr>
		<td align="left">&nbsp;</td>
	  </tr>
	<tr>
	<td style="padding-top:20px; padding-bottom:20px;"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
	  <tr>
	  		<td>
				<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
          <tr>
            <td width="5" height="99">&nbsp;</td>
            <td width="589" valign="top" style="padding-top:2px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center" class="ERR" style="padding-left:300px;">
					<?php 
					if($_REQUEST[msg]=="errorInsert") 
					echo "Error Occured During Insertion.......";
					if($_REQUEST[msg]=="errorUpdate") 
					echo "Error Occured During Updation.......";
					?>
					</td>
				</tr>
				<tr>
					<td><input class="buttonbg" type="button" name="continue_shopping" value="<?php echo CHECK_CONTINUE_SHOPPING; ?>" onClick="javascript:document.location='buy_spaceNew.php'"></td>
				<tr>
				<tr>
					<td  align="right" style="padding-left:300px;"><span style="font-size:12px;"><font color="#FF0000"><?php echo ALL_FIELD_REQUIRED; ?></font> </span></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
				<tr>
                <tr>
                  <td valign="top" class="tblBorder"><table width="100%" border="0" cellspacing="0" cellpadding="5">
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                          <tr>
                            <td height="25" class="listHeader" style="padding-left:10px;" bgcolor="#282A27"><?php echo SHIPPING_BILLING_INFO; ?></td>
                          </tr>
                          <tr>
                            <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td valign="top">&nbsp;</td>
                              </tr>
                              <tr>
                                <td class="headertext">&nbsp;&nbsp;<?php echo SHIPPING_BILLING_INFO_SAME; ?>&nbsp;&nbsp;<input type="checkbox" name="same" value="" onClick="shippBillSame();">&nbsp;</td>
                              </tr>
							 <tr>
                                <td valign="top">&nbsp;</td>
                              </tr>
								<tr>
                                <td class="ERR" align="center" style="padding-bottom:10px;"><font id="text_val"></font></td>
                              </tr>
                            </table></td>
                          </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td valign="top" align="center" width="80%"><table width="98%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td width="49%" valign="top"><table width="100%" border="1" cellspacing="0" cellpadding="0" class="login_txt">
                                  <tr>
                                    <td width="100%" class="boderbox"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                          <td width="100%" background="images/top-header1.gif" class="topheader"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                              <tr>
                                                <td height="32" class="listHeader"  bgcolor="#282A27" style="padding-left:10px;"><?php echo BILLING_INFO; ?> </td>
                                              </tr>
                                          </table></td>
                                        </tr>
                                        <tr>
                                          <td style="padding-right:10px;padding-left:10px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                          <tr> 
                                                            <td width="3%">&nbsp;</td>
                                                            <td width="35%">&nbsp;</td>
                                                            <td width="62%">&nbsp;</td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2" nowrap><?php echo BILLING_FIRST_NAME; ?><font color="#FF0000">*</font>: </td>
                                                            <td height="30"><input name="billing_fname"  value="<?php echo $billing_fname;?>" type="text" id="textfield3" class="InputBox" style="width:150px;" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo BILLING_LAST_NAME; ?><font color="#FF0000">*</font>: </td>
                                                            <td height="30"><input name="billing_lname" value="<?php echo $billing_lname;?>" type="text" class="InputBox" style="width:150px;" id="textfield5" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo BILLING_COMPANY; ?>: 
                                                            </td>
                                                            <td height="30"><input name="billing_company" value="<?php echo $billing_company;?>" type="text" class="InputBox" style="width:150px;" id="textfield6" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo BILLING_ADDRESS1; ?><font color="#FF0000">*</font>: 
                                                            </td>
                                                            <td height="30"><input name="billing_address1" value="<?php echo $billing_address1;?>" type="text" class="InputBox" style="width:150px;" id="textfield7" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo BILLING_ADDRESS2; ?>: 
                                                            </td>
                                                            <td height="30"><input name="billing_address2" value="<?php echo $billing_address2;?>" type="text" class="InputBox" style="width:150px;" id="textfield7" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td height="30" valign="top" class="text2"><?php echo BILLING_CITY; ?><font color="#FF0000">*</font>: 
                                                            </td>
                                                            <td><input name="billing_city" value="<?php echo $billing_city;?>" type="text" class="InputBox" style="width:150px;" id="textfield4" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo BILLING_COUNTRY; ?><font color="#FF0000">*</font>:</td>
                                                            <td height="35">
															<!--onChange="ajaxstate(this.value);"-->
															<select name="billing_country"  class="InputBox" style="width:160px;" onChange="ajaxstate(this.value)">
                                                                <option value="">--Select--</option>
																<?php
																
																	$sql = mysql_query("select * from country");
																
																while($res= mysql_fetch_array($sql)){
																?>
																<option value="<?php echo $res['countryId']; ?>" <?php echo $res['countryId']==$billing_country?'selected':'';?>> 
																<?php echo stripslashes($res['countryName']); ?>
																</option>
																<?php
																}
																?>
                                                              </select>
															</td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo BILLING_STATE; ?>:</td>
                                                            <td height="30">
															<div id="sltGeneral" >
															<?php
															if($billing_country!="")
															{
																
//echo "SELECT *  FROM state WHERE country_code ='".$billing_country."' ";
														$state_rs = mysql_query("SELECT *  FROM state WHERE country_code ='".$billing_country."'");
																//$state_rs = mysql_query("SELECT *  FROM add_state_master");
															}
															else
															{
																$state_rs = mysql_query("SELECT *  FROM state ");
//echo "SELECT *  FROM state ";
															}
															?>
                                                              <select  name="billing_state" class="InputBox" style="width:150px;" id="billing_state">
                                                                <option value="" class="linktext">Select a State</option>
																<?php
																while($state_row = mysql_fetch_array($state_rs))
																{
																?>
																<option value="<?php echo $state_row[stateId]; ?>" <?php echo $state_row['stateId']== $billing_state?'selected':''?>> 
																<?php echo stripslashes($state_row['state_name']); ?>
																</option>
																<?php
																}
																?>
                                                              </select>
															   </div>
															 <div align="left" id="sltOnChange"></div>
															  </td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo BILLING_ZIP; ?><font color="#FF0000">*</font>: </td>
                                                            <td height="30" class="linktext"><input name="billing_zipcode" value="<?php echo $billing_zip;?>" type="text" class="InputBox" style="width:150px;" id="textfield8"/></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo BILLING_PHONE; ?><font color="#FF0000">*</font>: 
                                                            </td>
                                                            <td height="30" class="linktext"><input name="billing_phone" value="<?php echo $billing_phone;?>" type="text" class="InputBox" style="width:150px;" id="textfield9" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo BILLING_FAX; ?>:</td>
                                                            <td height="30" class="linktext"><input name="billing_fax" value="<?php echo $billing_fax;?>" type="text" class="InputBox" style="width:150px;" id="textfield10" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2" nowrap><?php echo BILLING_EMAIL; ?><font color="#FF0000">*</font>: </td>
                                                            <td height="30" class="linktext"><input name="billing_email" value="<?php echo $billing_email;?>" type="text" class="InputBox" style="width:150px;" id="textfield11" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2">&nbsp;</td>
                                                            <td height="30" class="linktext style1">&nbsp;</td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2">&nbsp;</td>
                                                            <td height="30" class="linktext">&nbsp;</td>
                                                          </tr>
                                                        </table></td>
                                        </tr>
                                    </table></td>
                                  </tr>
                                 
                                </table></td>
                                <td>&nbsp;</td>
                                <td width="50%" valign="top"><table width="100%" cellspacing="0" cellpadding="0" border="1" class="login_txt">
                                  <tr>
                                    <td width="100%" class="boderbox"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>

                                          <td width="100%" background="images/top-header1.gif" class="topheader"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                              <tr>
                                                <td height="32" class="listHeader"  bgcolor="#282A27" style="padding-left:10px;"><?php echo SHIPPING_INFO; ?></td>
                                              </tr>
                                          </table></td>
                                        </tr>
                                        <tr>
                                          <td valign="top" style="padding-right:10px;padding-left:10px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                          <tr> 
                                                            <td width="3%">&nbsp;</td>
                                                            <td width="35%">&nbsp;</td>
                                                            <td width="62%">&nbsp;</td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2" nowrap><?php echo SHIPPING_FIRST_NAME; ?><font color="#FF0000">*</font>: </td>
                                                            <td height="30"><input name="shipping_fname" type="text" class="InputBox" style="width:150px;" id="textfield32" value="<?php echo $shipping_fname; ?>" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2" nowrap><?php echo SHIPPING_LAST_NAME; ?><font color="#FF0000">*</font>: </td>
                                                            <td height="30"><input name="shipping_lname" type="text" class="InputBox" style="width:150px;" id="textfield52"  value="<?php echo $shipping_lname;?>"/></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo SHIPPING_COMPANY; ?>: 
                                                            </td>
                                                            <td height="30"><input name="shipping_company" type="text" class="InputBox" style="width:150px;" id="textfield62" value="<?php echo $shipping_company; ?>" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo SHIPPING_ADDRESS1; ?><font color="#FF0000">*</font>: 
                                                            </td>
                                                            <td height="30"><input name="shipping_address1" type="text" class="InputBox" style="width:150px;" id="textfield72"  value="<?php echo $shipping_address1; ?>"/></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo SHIPPING_ADDRESS2; ?>: 
                                                            </td>
                                                            <td height="30"><input name="shipping_address2" type="text" class="InputBox" style="width:150px;" id="textfield72"  value="<?php echo $shipping_address2; ?>"/></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td height="30" valign="top" class="text2"><?php echo SHIPPING_CITY; ?><font color="#FF0000">*</font>: 
                                                            </td>
                                                            <td><input name="shipping_city" type="text" class="InputBox" style="width:150px;" id="textfield42" value="<?php echo $shipping_city; ?>" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo SHIPPING_COUNTRY; ?><font color="#FF0000">*</font>:</td>
                                                            <td height="35">
															<!--onChange="ajaxstate1(this.value);"-->
															<select name="shipping_country"  class="InputBox" style="width:160px;" onChange="ajaxstate1(this.value)">
                                                                <option value="">--Select--</option>
																	<?php $sql = mysql_query("select * from country ");

																	while($res= mysql_fetch_array($sql)){
																	?>
																	<option value="<?php echo $res['countryId']; ?>" <?php echo $res['countryId'] ==$shipping_country?'selected':''?>> 
																	<?php echo $res['countryName']; ?>
																	</option>
																	<?php }
																	?>
                                                              </select> 
															 </td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo SHIPPING_STATE; ?>:</td>
                                                            <td height="30"> 
															<div id="sltGeneral1" >
															<?php if($shipping_country!="")
															{
																//$state_rs = mysql_query("SELECT *  FROM add_state_master");
//echo "SELECT *  FROM state where countryId='".$shipping_country."'";
																$state_rs = mysql_query("SELECT *  FROM state where country_code='".$shipping_country."'");
															}
															else
															{
																$state_rs = mysql_query("SELECT *  FROM state");
															}
															?>
															<select  name="shipping_state" class="InputBox" style="width:150px;" id="shipping_state">
															<option value="">Select 
															a State</option>
															<?php while($state_row = mysql_fetch_array($state_rs))
															{
															?>
															<option value="<?php echo $state_row[stateId]; ?>" <?php echo $state_row['stateId']==$shipping_state?'selected':''?>> 
															<?php echo $state_row['state_name'] ; ?></option>
															<?php }
															?>
															</select></div>
															<div align="left" id="sltOnChange1"></div>
															</td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo SHIPPING_ZIP; ?><font color="#FF0000">*</font>: </td>
                                                            <td height="30" class="linktext"><input name="shipping_zipcode" type="text" class="InputBox" style="width:150px;" id="textfield82"  value="<?php echo $shipping_zip; ?>"/></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo SHIPPING_PHONE; ?><font color="#FF0000">*</font>: 
                                                            </td>
                                                            <td height="30" class="linktext"><input name="shipping_phone" type="text" class="InputBox" style="width:150px;" id="textfield92" value="<?php echo $shipping_phone; ?>" /></td>
                                                          </tr>
                                                          <tr> 

                                                            <td>&nbsp;</td>
                                                            <td class="text2"><?php echo SHIPPING_FAX; ?>:</td>
                                                            <td height="30" class="linktext"><input name="shipping_fax" type="text" class="InputBox" style="width:150px;" id="textfield102" value="<?php echo $shipping_fax; ?>" /></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2" nowrap><?php echo SHIPPING_EMAIL; ?><font color="#FF0000">*</font>: </td>
                                                            <td height="30" class="linktext"><input name="shipping_email" type="text" class="InputBox" style="width:150px;" id="textfield112"  value="<?php echo $shipping_email; ?>"/></td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2">&nbsp;</td>
                                                            <td height="30" class="linktext style1">&nbsp;</td>
                                                          </tr>
                                                          <tr> 
                                                            <td>&nbsp;</td>
                                                            <td class="text2">&nbsp;</td>
                                                            <td height="30" class="linktext">&nbsp;</td>
                                                          </tr>
                                                        </table></td>
                                        </tr>
                                    </table></td>
                                  </tr>
                                 
                                </table></td>
                              </tr>
                            </table></td>
                      </tr>
                     
                  </table></td>
                </tr>
				<tr>
					<td>&nbsp;</td>
				<tr>
				<tr>
					<td><input class="buttonbg" type="button" name="continue_shopping" value="<?php echo CHECKOUT_NOW; ?>" onClick="return checkFields();"></td>
				<tr>
            </table>
              </td>
            <td width="3">&nbsp;</td>
          </tr>
        </table>
			</td>
	  </tr>
	</table></td>
	</tr>
</table>
</form>
</td>
                      </tr>
                      <tr>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
                              <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                              <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
                            </tr>
                        </table></td>
                      </tr>
                    </table>

</td>
                    <td>&nbsp;</td>
                    </tr>
                </table></td>
              </tr>
            </table>
<!--</form>-->
<?php }
function insert_shipping_billing()
{
	
 $sql_user="select * from payment_method where userId='".$_SESSION['siteuserId']."' ";
$query_user=mysql_query($sql_user);
 $num_user=mysql_num_rows($query_user);
 if(empty($_REQUEST['shipping_state']))
 {
 	$shipping_state="0";	
 }
 if($num_user>0)
	{
	
		$sqlUpdateShipping ="update payment_method  set billing_fname='".$_REQUEST[billing_fname]."'";
		$sqlUpdateShipping .=", billing_lname='".$_REQUEST[billing_lname]."'";
		$sqlUpdateShipping .=", billing_company='".$_REQUEST[billing_company]."'";
		$sqlUpdateShipping .=", billing_address1='".$_REQUEST[billing_address1]."'";
		$sqlUpdateShipping .=", billing_address2='".$_REQUEST[billing_address2]."'";
		$sqlUpdateShipping .=", city='".$_REQUEST[billing_city]."'";
		$sqlUpdateShipping .=", country='".$_REQUEST[billing_country]."'";
		$sqlUpdateShipping .=", state='".$_REQUEST[billing_state]."'";
		$sqlUpdateShipping .=", zip='".$_REQUEST[billing_zipcode]."'";
		$sqlUpdateShipping .=", billing_phone='".$_REQUEST[billing_phone]."'";
		$sqlUpdateShipping .=", billing_fax='".$_REQUEST[billing_fax]."'";
		$sqlUpdateShipping .=", billing_email='".$_REQUEST[billing_email]."'";
		$sqlUpdateShipping .=", shipping_fname='".$_REQUEST[shipping_fname]."'";
		$sqlUpdateShipping .=", shipping_lname='".$_REQUEST[shipping_lname]."'";
		$sqlUpdateShipping .=", shipping_company='".$_REQUEST[shipping_company]."'";
		$sqlUpdateShipping .=", shipping_address1='".$_REQUEST[shipping_address1]."'";
		$sqlUpdateShipping .=", shipping_address2='".$_REQUEST[shipping_address2]."'";
		$sqlUpdateShipping .=", shipping_city='".$_REQUEST[shipping_city]."'";
		$sqlUpdateShipping .=", shipping_country='".$_REQUEST[shipping_country]."'";
		$sqlUpdateShipping .=", shipping_state='".$shipping_state."'";
		$sqlUpdateShipping .=", shipping_zip='".$_REQUEST[shipping_zipcode]."'";
		$sqlUpdateShipping .=", shipping_phone='".$_REQUEST[shipping_phone]."'";
		$sqlUpdateShipping .=", shipping_fax='".$_REQUEST[shipping_fax]."'";
		$sqlUpdateShipping .=", shipping_email='".$_REQUEST[shipping_email]."'";

		$sqlUpdateShipping .="  where userId='".$_SESSION[siteuserId]."'";

		//echo $sqlUpdateShipping;die;

		if(mysql_query($sqlUpdateShipping) or die(mysql_error()))//insert into shipping table
		{
                    $_SESSION[billing_id]=mysql_insert_id();
                    echo "<script language='javascript'>document.location='checkout_final.php?tab=buy_ads&subMenu=1'</script>";
		}
		else
		{
                    echo "<script language='javascript'>document.location='checkout.php?msg=errorUpdate&tab=buy_ads&subMenu=1'</script>";
		} 
	}
	else
	{		
		$sqlInsertShipping ="insert into payment_method  set billing_fname='".$_REQUEST[billing_fname]."'";
		$sqlInsertShipping .=", billing_lname='".$_REQUEST[billing_lname]."'";
		$sqlInsertShipping .=", userId='".$_SESSION[siteuserId]."'";
		$sqlInsertShipping .=", billing_company='".$_REQUEST[billing_company]."'";
		$sqlInsertShipping .=", billing_address1='".$_REQUEST[billing_address1]."'";
		$sqlInsertShipping .=", billing_address2='".$_REQUEST[billing_address2]."'";
		$sqlInsertShipping .=", city='".$_REQUEST[billing_city]."'";
		$sqlInsertShipping .=", country='".$_REQUEST[billing_country]."'";
		$sqlInsertShipping .=", state='".$_REQUEST[billing_state]."'";
		$sqlInsertShipping .=", zip='".$_REQUEST[billing_zipcode]."'";
		$sqlInsertShipping .=", billing_phone='".$_REQUEST[billing_phone]."'";
		$sqlInsertShipping .=", billing_fax='".$_REQUEST[billing_fax]."'";
		$sqlInsertShipping .=", billing_email='".$_REQUEST[billing_email]."'";
		$sqlInsertShipping .=", shipping_fname='".$_REQUEST[shipping_fname]."'";
		$sqlInsertShipping .=", shipping_lname='".$_REQUEST[shipping_lname]."'";
		$sqlInsertShipping .=", shipping_company='".$_REQUEST[shipping_company]."'";
		$sqlInsertShipping .=", shipping_address1='".$_REQUEST[shipping_address1]."'";
		$sqlInsertShipping .=", shipping_address2='".$_REQUEST[shipping_address2]."'";
		$sqlInsertShipping .=", shipping_city='".$_REQUEST[shipping_city]."'";
		$sqlInsertShipping .=", shipping_country='".$_REQUEST[shipping_country]."'";
		$sqlInsertShipping .=", shipping_state='".$shipping_state."'";
		$sqlInsertShipping .=", shipping_zip='".$_REQUEST[shipping_zipcode]."'";
		$sqlInsertShipping .=", shipping_phone='".$_REQUEST[shipping_phone]."'";
		$sqlInsertShipping .=", shipping_fax='".$_REQUEST[shipping_fax]."'";
		$sqlInsertShipping .=", shipping_email='".$_REQUEST[shipping_email]."'";
		if(mysql_query($sqlInsertShipping) or die(mysql_error()))//insert into shipping table
		{
                    echo "<script language='javascript'>document.location='checkout_final.php?tab=buy_ads&subMenu=1'</script>";
		}
		else{
                    echo "<script language='javascript'>document.location='checkout.php?msg=errorInsert&tab=buy_ads&subMenu=1'</script>";
		}
	}
}
?>